package com.panda.web.mapper.order;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.panda.web.domain.dto.OrderDTO;
import com.panda.web.domain.vo.OrderVO;
import com.panda.web.entity.order.WechatOrder;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.List;

/**
 * 微信支付订单Mapper接口
 *
 * @author cpanda
 * @date 2025-02-27
 */
@Mapper
public interface WechatOrderMapper extends BaseMapper<WechatOrder> {
    @Select("select *from wechat_order where out_trade_no =#{orderId}")
    WechatOrder findByOrderId(String orderId);

    @Select("select SUM(total_fee) from wechat_order where pay_status ='已支付' and refund_status='未退款' ")
    BigDecimal selectYZFWTK();

    @Select("SELECT COUNT(*) FROM wechat_order WHERE product_id = #{productId} and pay_time like concat('%',#{today},'%')  AND pay_status = '已支付'")
    Integer findByProductId(
            @Param("productId") Long productId,
            @Param("today") String today
    );

    @Select("SELECT COUNT(*) FROM wechat_order WHERE product_id = #{productId} AND pay_time BETWEEN #{startTime} AND #{endTime} AND pay_status = '已支付'")
    Integer findByProductIdBETWEEN(
            @Param("productId") Long productId,
            @Param("startTime") String startTime,
            @Param("endTime") String endTime
    );
    @Select("select * from wechat_order where openid=#{openid} and pay_status ='已支付'")
    List<WechatOrder> findByOpenid(String openid);

    IPage<OrderVO> selectOrderPage(IPage<?> page, @Param("dto") OrderDTO dto);
}
